# link the proto file to the current directory
ln -s ../src/main/proto/hi.proto hi.proto


# echo generated_pb/ >> .gitignore
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
export PATH=$PATH:$(go env GOPATH)/bin
n=generated_pb
mkdir $n
protoc --go_out=$n --go_opt=paths=source_relative \
       --go-grpc_out=$n --go-grpc_opt=paths=source_relative \
       hi.proto
# 🦜 : Remember to generate the protobuf files before `go mod tidy`
go mod tidy

go run . --safety=2 --mockMore=true # for showcasing
go run . --safety=2             # for testing
# 🦜 :[2024-03-02] we updated to add bpf
go build
sudo ./a.local
sudo ./a.local --safety=2

./a.local --safety=2 --mockMore=true
./a.local --safety=1            # enable bash_history

# go install github.com/ktr0731/evans@latest
E2=(evans --host localhost --port 50051 --proto ./hi.proto)

# 🦜 : Try the remote server
n=192.168.31.100
E2=(evans --host $n --port 50051 --proto ./hi.proto)

# E2=(evans --host localhost --port 50051)
echo '{"name": "aaa"}' | $E2 cli call Greeter.ChangeRootPswd
echo '{}' | $E2 cli call Greeter.GetUsers 
echo '{}' | $E2 cli call Greeter.StreamOneoffProcessInfo 
echo '{"name" : ""}' | $E2 cli call Greeter.StreamFileIO 

# --------------------------------------------------
# scp to update the remote server
h=[fd00::116]
scp ./sub/s.go "root@$h:/root/音乐/managed-server/go-agent/sub/s.go"

# there
# 1. stop the service
p=8000
curl localhost:$p/basic/bye
# 2. rebuild
cd /root/音乐/managed-server/go-agent
go build
./a.local --safety=1
# 🦜 : Oh, it turns out that we only `ps` 20 minutes a day...


# --------------------------------------------------
# github.com/iovisor/gobpf/bcc
# /home/me/go/pkg/mod/github.com/iovisor/gobpf@v0.2.0/bcc/module.go:32:10: fatal error: bcc/bcc_common.h: No such file or directory
# 32 | #include <bcc/bcc_common.h>
#     |          ^~~~~~~~~~~~~~~~~~
# compilation terminated.
sudo -E apt update
sudo apt install libbpfcc-dev
go build .


go run . --safety=2             # for testing

go build                        # ❌️: this build dynamically-linked executable
CGO_ENABLED=0 go build -o a.local.0 # ✅️ : this build the static one, a bit more portable

# 🦜 : Okay... doesn't seem to work with bpf-go...Nor does the following...
# CGO_ENABLED=0 go build -o a.local.o -a -ldflags '-extldflags "-static"' . 
